
<table class="rangePicsTable">
    <tr>
        <th>
            <input id="rangePicsCheckbox" type="checkbox" title="вкл/выкл" checked="checked" onchange="rangePicsToggle()" />
            <label for="rangePicsCheckbox">вкл./выкл. все:</label>
        </th>
    </tr>
</table>
<div id="rangePics">
    <?php if ( !empty( $comfort ) ):
            $comfort_names = array();
            foreach ( $comfort as $item ):
                $comf = $item instanceof sfOutputEscaperIteratorDecorator ? $item->getRawValue()->getLodgingComfort() : $item->getLodgingComfort();
                array_push( $comfort_names, $comf ) ?>
                <div class="comf" onclick="toggleComf( $(this), '<?php echo $item->getLodgingComfort() ?>' )">
                    <div id="comf_<?php echo $item->getLodgingComfort() ?>" class="comf_off"></div>
                    <div class="comf_<?php echo $item->getLodgingComfort() ?>" title="<?php echo $item->getLodgingComfortName() ?>"></div>
                </div>
    <?php   endforeach ?>
    <?php endif ?>
</div>
<div class="clear"></div>

<script language="javascript" type="text/javascript">

    var comfort;

    function toggleComf( comfObj, comf )
    {
        $('#comf_'+comf).toggle();

        index = $.inArray(comf, comfort);

        if ( index >= 0 )
        	comfort.splice( index, 1 );
        else
        	comfort.push(comf);
    }

    function rangePicsToggle()
    {
        if ( $('#rangePicsCheckbox').is(':checked') )
        {
            $(".comf_off").hide();
            comfort = <?php echo empty( $comfort_names ) ? "[]" : "['".implode( "','", $comfort_names )."']" ?>;
        }
        else
        {
            $(".comf_off").show();
            comfort = [];
        }
    }

    $(function() {
        rangePicsToggle();
    });

</script>
